//###############
// FILE : Filter.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION: Abstract filter class, different filters for file properties.
//###############
package oop.ex3.fileSearchModel.filters;
import java.io.*;

import oop.ex3.fileSearchModel.filters.exceptions.*;

import java.util.ArrayList;

/**
 * Abstract filter class, different filters for file properties.
 */
public abstract class Filter implements Conditionable {
   
	//***********************************************************************
	//  Data members :                                                      *
	//***********************************************************************
	protected STATUS _condition;
    protected File _file;
    protected String _data;
    
    //***********************************************************************
	//  Methods :                                                           *
	//***********************************************************************
    
    /**
     * Constructs a new filter.
     */
    public Filter(){
        _condition = STATUS.UNKNOWN;
    }
    
    /**
     * Returns the status of the filter checked on the given file.
     * @return Status of the filter checked on the given file.
     * @throws FilterDataException In case of wrong filter parameters. 
     */
    public STATUS getCondition() throws FilterDataException{
    	if (_condition == Conditionable.STATUS.UNKNOWN){
			calculate();
		}
		return _condition;
	}
    /**
     * Calculate and set the condition status of the filter.
     * @throws FilterDataException In case of wrong filter parameters. 
     */
    public abstract void calculate() throws FilterDataException;
	/**
	 * Sets condition's data.
	 * @param status The status to be set.
	 */
    public void setCondition(STATUS status) {
        _condition = status;
    }
    /**
     * Resets the filter.
     * @param resetData Data of the reset filter.
     * @param source Source direcotory.
     */
	public void reset(File resetData, String source){
		_condition = STATUS.UNKNOWN;
		setFile( resetData );
	}
	/**
	 * Returns filter's value
	 * @return Filter's value.
	 */
	public String getData(){
		return _data;
	}
	/**
	 * Returns a list with all the byte filters.
	 * @return A list with all the byte filters.
	 */
    public ArrayList<Filter> getByteList(){
        return new ArrayList<Filter>();
    }
    /**
     * Returns a list with all the byte filters.
     * @return A list with all the byte filters.
     */
    public ArrayList<Filter> getTextList(){
        return new ArrayList<Filter>();    }
	/**
	 * Return a clone of the filter.
	 * @return A clone of the filter.
	 */
	public abstract Filter clone();
	/**
	 * Returns Filter's checking file.
	 * @return Filter's checking file.
	 */
	public File getFile() {
	    return _file;
	}
	/**
	 * Sets the filter checking file.
	 * @param file Filter's checking file.
	 */
	public void setFile(File file) {
	    _file = file;
	}
	/**
	 * Sets the data of the filter.
	 * @param data The data to be set.
	 */
	public abstract void setData( String data ) throws FilterDataException;
}
